
<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
        <meta name="description" content="">
        <meta name="author" content="">

        <title>{$sysPageTitle}</title>

        <link href="__PUBLIC__/images/favicon.ico" rel="shortcut icon" />

        <!-- Bootstrap core CSS -->
        <link rel="stylesheet" href="__PUBLIC__/css/bootstrap.min.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/bootstrap-theme.min.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/dashboard.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/bootstrap-switch.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/icheck/all.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/bootstrap-datetimepicker.css" />
        <link rel="stylesheet" href="__PUBLIC__/js/bootstrapvalidator/css/bootstrapValidator.min.css" />
    </head>

    <body>

    <include file="Common/topNav" />

    <div class="container-fluid">
        <div class="row">
            <include file="Common/leftMenu" />
            <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
                <div class="cont-title clearfix">
                    <div class="title">用户列表</div>
                    <div class="btn-group"><button type="button" id="addUser"  class="btn">添加用户</button></div>
                </div>
                
                <form class="jc-search form-inline searchForm" action="{:U('Admin/User/index')}" method="post">
                    <if condition="$Think.session.default_module == 'Space'">
                        <div class="form-group">
                            <label>所属团队:</label>
                            <select class="form-control" name="team_id" >
                                <option value="">全部</option>
                                <volist name="teamList" id="team">
                                    <option <if condition="$team_id eq $team['id']">selected="selected"</if> value="{$team.id}">{$team.team_name}</option>
                                </volist>
                            </select>
                        </div>
                    </if>
                    <div class="form-group">
                        <label>用户组:</label>
                        <select class="form-control" name="role_id" >
                            <option value="">全部</option>
                            <volist name="roleList" id="role">
                                <option <if condition="$role_id eq $role['id']">selected="selected"</if> value="{$role.id}">{$role.name}</option>
                            </volist>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>真实姓名:</label>
                        <input type="text" class="form-control" name="real_name" value="{$real_name}" placeholder="输入真实姓名">
                    </div>
                    <div class="form-group">
                       <label>手机号:</label>
                        <input type="text" class="form-control" name="mobile" value="{$mobile}" placeholder="输入手机号">
                    </div>
                    <div class="form-group">
                        <label>状态:</label>
                        <select class="form-control" name="status" >
                            <option value="-1">全部</option>
                            <option <if condition="$status eq '1'">selected="selected"</if> value="1">启用</option>
                            <option <if condition="$status eq '0'">selected="selected"</if> value="0">禁用</option>
                        </select>
                    </div>

                    <input class="btn" type="submit" value="搜索" />
                </form>
                
                <div class="table-responsive" style="overflow: visible;">
                    <table class="table table-striped table-hover" id="tableData">
                        <thead>
                            <tr>
                                <th>序号</th>
                                <th>用户名</th>
                                <th>登录账号</th>
                                <th>手机号</th>
                                <th>角色</th>
                                <th>启用状态</th>
                                <th>认证状态</th>
                                <th>审核状态</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody id="user_list">
                        <volist name="data['list']" id="user">
                            <tr>
                                <td>{$user.id}</td>
                                <td>{$user.real_name}</td>
                                <td>{$user.user_name}</td>
                                <td>{$user.mobile}</td>
                                <td>{$user.role.name|default="-"}</td>
                                <td>
                                    <if condition="$user.status eq 1">
                                        <span class="label label-success">启用</span>
                                    <else/>
                                        <span class="label label-danger">禁用</span>
                                    </if>
                                </td>
                                <td>
                                    <if condition="$user.real_name && $user.mobile && $user.identity">
                                        <span class="label label-success">已认证</span>
                                    <else/>
                                        <span class="label label-danger">未认证</span>
                                    </if>
                                </td>
                                <td class="status_content" <if condition="$user['state'] eq 2">title="{$user.real_name|default=$user['user_name']}" data-toggle="popover" data-content="{$user.remark|default='其它'}"</if>>
                                    <if condition="$user['role']['super'] eq 0">
                                        <div class="btn-group" style="margin-top:-5px;margin-bottom:-5px;">
                                            <button type="button" onclick="chooseThis(this)" class="btn btn-link dropdown-toggle" data-toggle="dropdown" style="margin-top: -2px;text-decoration:none; ">
                                                <switch name="user.state">
                                                    <case value="0"><span class="label label-info">审核中</span></case>
                                                    <case value="1"><span class="label label-success">审核通过</span></case>
                                                    <case value="2"><span class="label label-danger">审核未通过</span></case>
                                                </switch>
                                            </button>
                                            <ul class="dropdown-menu" style="font-size: 14px;">
                                                <li><a href="javascript:void(0);" id="{$user.id}" statusId="0" onclick="setStatus(this)">审核中</a></li>
                                                <li><a href="javascript:void(0);" id="{$user.id}" statusId="1" onclick="setStatus(this)">审核通过</a></li>
                                                <li><a href="javascript:void(0);" id="{$user.id}" statusId="2" onclick="setStatus(this)">审核未通过</a></li>
                                            </ul>
                                        </div>
                                    </if>
                                </td>
                                <td>{$user.create_time|date='Y-m-d H:i:s',###}</td>
                                <td>
                                    <if condition="$user['role']['super'] eq 0">
                                        <a href="javascript:void(0)" userId="{$user.id}" class="editUser">修改</a> |
                                        <a href="javascript:void(0)" userId="{$user.id}" class="resetPass">重置密码</a> |
                                        <if condition="$user['status'] eq 1">
                                            <a href="javascript:void(0)" userId="{$user.id}" class="deUser">禁用</a> |
                                        <else />
                                            <a href="javascript:void(0)" userId="{$user.id}" class="enUser">启用</a> |
                                        </if>
                                        <a href="javascript:void(0)" userId="{$user.id}" class="vouchers">发放通话券</a>
                                    </if>
                            </td>
                            </tr>
                        </volist>    
                        </tbody>
                    </table>
                    <div class="page">
                    	{$data.page}
                    </div>
                </div>
            </div>
        </div>
    </div>
    <include file="Common/modalHtmls" />
    <script type="text/javascript" src="__PUBLIC__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/bootstrap-switch.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/icheck.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/validator.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/bootstrap-datetimepicker.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/bootstrapvalidator/js/bootstrapValidator.min.js"></script>
    <script>
        $(".status_content").popover({
            trigger: "hover",
            container: "body",
            placement: "right"
        });

        //

        $("#tableData").on("click",".vouchers",function () {
            var userId = $(this).attr("userId");
            common.htmlAjax("{:U('Admin/User/vouchers')}", {userId: userId}, function (html) {
                $("#commonModal").html(html).modal({show: true, backdrop: 'static', keyboard: false});
            })
        })

        $("#tableData .editUser").click(function () {
            var userId = $(this).attr("userId");
            //console.log(userId);
            common.htmlAjax("{:U('Admin/User/editUser')}", {userId: userId}, function (html) {
                $("#commonModal").html(html).modal({show: true, backdrop: 'static', keyboard: false});
            })
        })

        $("#addUser").click(function () {
            common.htmlAjax("{:U('Admin/User/addUser')}", {}, function (html) {
                $("#commonModal").html(html).modal({show: true, backdrop: 'static', keyboard: false});
            })
        })
        
        $("#tableData .resetPass").click(function () {
            var userId = $(this).attr("userId");
            common.confirm("提示", "确定重置用户密码?", function () {
                common.ajax("{:U('Admin/User/resetUserPass')}", {userId: userId}, function (data) {
                    //console.log(data);
                    common.alert("提示", "重置用户密码成功,密码已经改为123456!", function () {
                        common.reload();
                    });
                });
            });
        });

        $("#tableData .deUser").click(function () {
            var userId = $(this).attr("userId");
            common.confirm("提示", "确定禁用用户?", function () {
                common.ajax("{:U('Admin/User/deUser')}", {userId: userId}, function (data) {
                    //console.log(data);
                    common.alert("提示", "用户禁用成功!", function () {
                        common.reload();
                    });
                });
            });
        });

        $("#tableData .enUser").click(function () {
            var userId = $(this).attr("userId");
            common.confirm("提示", "确定启用用户?", function () {
                common.ajax("{:U('Admin/User/enUser')}", {userId: userId}, function (data) {
                    //console.log(data);
                    common.alert("提示", "用户启用成功!", function () {
                        common.reload();
                    });
                });
            });
        });

        function chooseThis(obj) {
            $("#user_list").find("tr").css({"background-color":""});
            $(obj).parents("tr").css({"background-color":"#D2ECF9"});
        }

        function setStatus(obj) {
            var statusId = $(obj).attr("statusId");
            var id = $(obj).attr("id");
            var statusName = $(obj).html();
            var msg = '确定将用户状态修改为【<span style="color:#FF0000;">'+statusName+'</span>】吗？';
            var span = '';
            switch(statusId) {
                case '0':
                    span = '<span class="label label-info">审核中</span>';
                    break;
                case '1':
                    span = '<span class="label label-success">审核通过</span>';
                    break;
                case '2':
                    span = '<span class="label label-danger">审核未通过</span>';
                    var remark = '请选择未通过原因：<div class="form-group" style="margin-top: 15px;"><select id="refuse_remark" class="form-control">';
                    remark += '<option value="禁止含有联系方式">1. 禁止含有联系方式</option>';
                    remark += '<option value="禁止使用国家领导人肖像">2. 禁止使用国家领导人肖像</option>';
                    remark += '<option value="禁止出现赌博、色情、暴力、侵权等信息">3. 禁止出现赌博、色情、暴力、侵权等信息</option>';
                    remark += '<option value="禁止出现共享机票官方信息">4. 禁止出现共享机票官方信息</option>';
                    remark += '</select></div>';
                    msg += remark;
                    break;
            }
            common.confirm("提示", msg, function () {
                $(obj).parent().parent().prev("button").html(span);
                var param = {id: id,statusId:statusId};
                if ($("#refuse_remark").length) {
                    param.remark = $("#refuse_remark").val();
                }
                common.ajax("{:U('Admin/User/setUserState')}", param);
            });
        }
    </script>
</body>
</html>
